﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for Common
/// </summary>
/// 

namespace vdos.jobseeker.CustomerView.Common
{
    public class Helper
    {
        public static string GeneratePageNavigationControl(int lCurrentPage, int lPageCount)
        {

            string temp = "";
            string temp0 = "";
            string temp1 = "";
            string temp2 = "";
            string temp3 = "";
            string temp4 = "";

            int canTren, canDuoi;
            canTren = lCurrentPage + 2; // Biến cận trên
            if (lPageCount - lCurrentPage == 0)
            {
                canTren = lPageCount;
                canDuoi = canTren - 2;
            }
            else if (lPageCount - lCurrentPage == 1)
            {
                canTren = lPageCount;
                canDuoi = canTren - 3;
            }

            else
            {
                canDuoi = canTren - 4;
            }
            if (canDuoi <= 0) canDuoi = 1;
            if (canDuoi > 1) temp1 = "<a href=\"javascript:setValue('1');\"> Đầu </a>&nbsp;";
            if (lCurrentPage > 3) temp2 += "<a href=\"javascript:setValue('" + (lCurrentPage - 3).ToString() + "');\"> ... </a>&nbsp;";

            for (int i = canDuoi; i <= canTren; i++)
            {
                if (i == lCurrentPage)
                {
                    temp0 += "<a class=\"current\"> " + i + " </a>&nbsp;";
                }
                else
                {
                    temp0 += "<a href=\"javascript:setValue('" + i + "');\"> " + i + " </a>&nbsp;";
                }


                if (lCurrentPage <= lPageCount - 3) temp3 = "<a href=\"javascript:setValue('" + (lCurrentPage + 3).ToString() + "');\"> ... </a>&nbsp;";
                if (canTren < lPageCount) temp4 = "<a href=\"javascript:setValue('" + lPageCount + "');\"> Cuối </a>&nbsp;";
            }

            return temp1 + temp2 + temp0 + temp3 + temp4;
        }

        public static string FormatCurrencyVND(object money)
        {
            try
            {
                if (money == null)
                    return "";
                else
                {
                    decimal value = Convert.ToDecimal(money)*1000; // đơn vị mặc định là nghìn đồng
                    string reval = String.Format("{0:0,0 đ}", value);
                    reval = reval.Replace(',', '.');

                    return reval;
                }
            }
            catch (Exception ex)
            {
                return "";
            }
        }
    }

}